home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
simplejson
/
scanner.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
2KB
|
72 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import re
from re import VERBOSE, MULTILINE, DOTALL
import sre_parse
import sre_compile
import sre_constants
from sre_constants import BRANCH, SUBPATTERN
__all__ = [
'make_scanner',
'pattern']
FLAGS = VERBOSE | MULTILINE | DOTALL
def make_scanner(lexicon, flags = FLAGS):
actions = [
None]
s = sre_parse.Pattern()
s.flags = flags
charpatterns = { }
p = []
idx = 0
for token in lexicon:
if token.pattern in ('\\[', '{', '"'):
charpatterns[token.pattern[-1]] = token
idx += 1
phrase = token.pattern
try:
subpattern = sre_parse.SubPattern(s, [
(SUBPATTERN, (idx, sre_parse.parse(phrase, flags)))])
except sre_constants.error:
raise
p.append(subpattern)
actions.append(token)
s.groups = len(p) + 1
p = sre_parse.SubPattern(s, [
(BRANCH, (None, p))])
scanner = sre_compile.compile(p).scanner
def _scan_once(string, idx = None, context = (None, 0, None)):
try:
action = charpatterns[string[idx]]
except KeyError:
pass
except IndexError:
raise StopIteration
return action((string, idx + 1), context)
m = scanner(string, idx).match()
if m is None or m.end() == idx:
raise StopIteration
return actions[m.lastindex](m, context)
return _scan_once
def pattern(pattern, flags = FLAGS):
def decorator(fn):
fn.pattern = pattern
fn.regex = re.compile(pattern, flags)
return fn
return decorator